public enum TestEnum {
    RED("red",1),BLACK("balck",2),GREEN("green",3),WHITE("white",4);// 颜色
    public String color;
    public int ordinal;

    private TestEnum(String color,int ordinal){
        // super()
        this.color = color;
        this.ordinal = ordinal;
    }


    // 枚举类可以有自己的 main 函数

    public static void main(String[] args) {

    }


    public static void main4(String[] args) {
        System.out.println(RED.compareTo(BLACK));
        System.out.println(RED.compareTo(WHITE));
        System.out.println(WHITE.compareTo(GREEN));
        System.out.println(WHITE.compareTo(BLACK));
    }

    public static void main3(String[] args) {
        // 把字符串 变成 对应 枚举对象
        TestEnum testEnum = TestEnum.valueOf("RED2");
        System.out.println(testEnum);
    }
    public static void main2(String[] args) {
        System.out.println("打乱顺序，输出每个枚举成员的索引位置，看看索引位置是否会因为打印的顺序不同而改变");
        System.out.println("BLACK:" + BLACK.ordinal());
        System.out.println("RED:" + RED.ordinal());
        System.out.println("WHITE:" +WHITE.ordinal());
        System.out.println("GREEN:"+GREEN.ordinal());
        TestEnum[] testEnums = TestEnum.values();
        System.out.println("下面是数组遍历枚举数组，输出每个枚举成员的索引位置：");
        for (int i = 0; i < testEnums.length; i++) {
            System.out.println(testEnums[i] + "->" +testEnums[i].ordinal());
        }
    }

    public static void main1(String[] args) {
        TestEnum testEnum2 = TestEnum.BLACK;
        switch (testEnum2) {
            case RED:
                System.out.println("red");
                break;
            case BLACK:
                System.out.println("black");
                break;
            case WHITE:
                System.out.println("WHITE");
                break;
            case GREEN:
                System.out.println("green");
                break;
            default:
                break;
        }
    }
}
